//
//  loginViewController.swift
//  Community
//
//  Created by JKSD on 2019/8/6.
//  Copyright © 2019 ZKJ. All rights reserved.
//

import UIKit

class SEPTloginViewController: UIViewController {

    @IBOutlet weak var login: UIButton!
    @IBOutlet weak var pas: UITextField!
    @IBOutlet weak var count: UITextField!
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "登录"
        self.login.layer.cornerRadius = 25
        self.login.clipsToBounds = true
    }

    //去登陆
    @IBAction func signIn(_ sender: Any) {
        
        if (pas.text == nil || pas.text! == "" || count.text == nil || count.text! == "" ) {
            LYProgressHUD.showMessage("请填写正确的账号和密码")
            return
        }
        
        
        let result = CoreDataManager.shared.check(count.text!, password: pas.text!)
        switch result {
        case .success(let user):
            let userModel = KIDUserModel.init()
            userModel.loginAccount = count.text
            userModel.saveOrUpdate()
            self.navigationController?.popViewController(animated: true)
        case .failure(let msg):
            LYProgressHUD.showMessage(msg)
   
            
        }
        
    }
    
    //去注册
    @IBAction func signUp(_ sender: Any) {
        self.navigationController?.pushViewController(SEPTregistViewController.init(), animated: true)
    }
    
}
